package ${package.Mapper};

import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import ${package.Entity}.${entity};
import ${superMapperClassPackage};
import ${package.queryPkg}.${query};
<#if mapperAnnotationClass??>
import ${mapperAnnotationClass.name};
</#if>

/**
 * <p>
 * ${table.comment!} Mapper 接口
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if mapperAnnotationClass??>
@${mapperAnnotationClass.simpleName}
</#if>
<#if kotlin>
interface ${table.mapperName} : ${superMapperClass}<${entity}>
<#else>
public interface ${table.mapperName} extends ${superMapperClass}<${entity}> {

    /**
     * 生成查询条件
     *
     * @param query 查询条件
     */
    static LambdaQueryWrapper<${entity}> createWrapper(${query} query) {
        LambdaQueryWrapper<${entity}> wrapper = Wrappers.lambdaQuery(${entity}.class);
        <#list table.fields as field>
        <#if field.propertyType == "boolean">
        <#assign getprefix="is"/>
        <#else>
        <#assign getprefix="get"/>
        </#if>
        <#if field.propertyType == "String">
        wrapper.like(StrUtil.isNotBlank(query.${getprefix}${field.capitalName}()), ${entity}::${getprefix}${field.capitalName}, query.${getprefix}${field.capitalName}());
        <#else>
        wrapper.eq(ObjUtil.isNotNull(query.${getprefix}${field.capitalName}()), ${entity}::${getprefix}${field.capitalName}, query.${getprefix}${field.capitalName}());
        </#if>
        </#list>
        return wrapper;
    }

}
</#if>
